package com.example.christina.service;

import com.example.christina.repository.ShopcartRepository;
import com.example.christina.enity.Shopcart;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShopcartService {

    @Autowired
    private ShopcartRepository shopcartRepository;

    public void addShopcart(Shopcart shopcart){
        shopcartRepository.save(shopcart);
    }

    public void deleteShopcart(Shopcart shopcart){
        shopcartRepository.delete(shopcart);
    }

    // 返回购买商品的数量
    public Integer goodNum(String goodname){return shopcartRepository.find(goodname);}

    public List<?> getShopcart(String username){return shopcartRepository.findByusername(username);}
}
